/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Pojo.Sach;
import Util.MySqlDataAccessHelper;

/**
 *
 * @author USER
 */
public class SachGiaoKhoaDAO extends SachDAO {

    public static boolean themSachGiaoKhoa(Sach s) {
        boolean kq = false;
        MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
        try {
            helper.open();
            //Thêm dữ liệu vào bảng sách.
            kq = SachGiaoKhoaDAO.themSach(s);
            String sql = String.format("INSERT INTO `sach_giao_khoa` (`ma_sach`,`ten_lop`) VALUES(%d, '%s')",
                    s.getMaSach(), s.getTenLop());
            kq = helper.executeNonQuery(sql);
            helper.close();
        } catch (Exception e) {
        } finally {
            helper.close();
        }
        return kq;
    }

    public static boolean capNhatSachGiaoKhoa(Sach s) {
        boolean kq = false;
        MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
        try {
            helper.open();
            //Cập nhật dữ liệu vào bảng sách.
            kq = SachDAO.capNhatSach(s);
            String sql = String.format("UPDATE `sach_giao_khoa` SET `ten_lop`='%s' WHERE `ma_sach`=%d", s.getTenLop(), s.getMaSach());
            kq = helper.executeNonQuery(sql);
            helper.close();
        } catch (Exception e) {
        } finally {
            helper.close();
        }
        return kq;
    }
}
